package com.testin.utils;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;


public class MysqlLoader {
   
	
	/**
	 * 根据sql执行
	 * @param sql
	 * @throws Exception
	 */
	public int saveData(String sql) throws Exception {
		Connection srcConn = null;
		Statement srcStmt = null;
		// PreparedStatement srcStmt=null;
		ResultSet srcResultSet = null;
		int foreignKeyId=0;
		ResultSet rs = null; 
		try {
			srcConn = DBUtils.getConnection();
			srcStmt = srcConn.createStatement(java.sql.ResultSet.TYPE_FORWARD_ONLY,java.sql.ResultSet.CONCUR_READ_ONLY);
			//srcStmt  =  srcConn.prepareStatement(sql,Statement.RETURN_GENERATED_KEYS);
			srcStmt.executeUpdate(sql,Statement.RETURN_GENERATED_KEYS);
			srcResultSet=srcStmt.getGeneratedKeys(); //获取
			srcResultSet.next();         
			foreignKeyId = srcResultSet.getInt(1); 
			//H2Utility.copyTable(srcResultSet, h2Stmt, tableName);
		}finally{
			if(srcResultSet!=null){
				srcResultSet.close();
			}
			if(srcStmt!=null){
				srcStmt.close();
			}
			if(srcConn!=null){
				srcConn.close();
			}
		}
		return foreignKeyId;
	}
	

}
